<!doctype html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
    <title>Document</title>
    <link th:href="@{/css/style.css}" rel="stylesheet"/>
</head>
<body>

<!-- sec 标签支持的最高springboot版本是2.0.9         -->
<!--isAuthenticated判断是否登录-->
<div sec:authorize="!isAuthenticated()">
    <a th:href="@{/toLogin}">登录</a>
</div>

<div sec:authorize="isAuthenticated()">
<!--    获得用户名字-->
    用户名：<span sec:authentication="name"></span>
<!--    获得用户权限-->
<!--    角色：<span sec:authentication=""></span>-->
    <a th:href="@{/logout}">注销</a>
</div>
<!--authorize 假如用户有vip1的角色  就显示-->
<div class="div" sec:authorize="hasRole('vip1')">
    <h3>level1</h3>
    <li><a th:href="@{/level1/1}">level1-1</a></li>
    <li><a th:href="@{/level1/2}">level1-2</a></li>
    <li><a th:href="@{/level1/3}">level1-3</a></li>
</div>
<div class="div" sec:authorize="hasRole('vip2')">
    <h3>level2</h3>
    <li><a th:href="@{/level2/1}">level2-1</a></li>
    <li><a th:href="@{/level2/2}">level2-2</a></li>
    <li><a th:href="@{/level2/3}">level2-3</a></li>
</div>
<div class="div" sec:authorize="hasRole('vip3')">
    <h3>level3</h3>
    <li><a th:href="@{/level3/1}">level3-1</a></li>
    <li><a th:href="@{/level3/2}">level3-2</a></li>
    <li><a th:href="@{/level3/3}">level3-3</a></li>
</div>

</body>
</html>